#!/bin/sh -x

# Oracle/prefix paths
PREFIX="${PKG_PREFIX}"
ORACLEPREFIX="/usr/lib/oracle"
ORADIR="${ORACLEPREFIX}/xe"

case $2 in
PRE-DEINSTALL)

#
# pre-uninstall script extracted from the OracleXE RPM package
# and adapted for FreeBSD environment
#

rm -f $ORADIR/app/oracle/product/10.2.0/server/network/admin/tnsnames.ora
rm -f $ORADIR/app/oracle/product/10.2.0/server/network/admin/listener.ora
rm -f $ORADIR/app/oracle/product/10.2.0/server/config/scripts/postDBCreation.sql

exit 0
;;

POST-DEINSTALL)

#
# post-uninstall script extracted from the OracleXE RPM package
# and adapted for FreeBSD environment
#

#XXX
/compat/linux/sbin/ldconfig >/dev/null

if [ -f /etc/oratab ]
then
	/usr/bin/sed -i ".xe" -s "/XE:${ORADIR}\/app\/oracle\/product\/10.2.0\/server:N/d" /etc/oratab.xe
fi

rm -fr $PKG_PREFIX/etc/oracle-xe

if test -d $ORADIR/oradata/XE
then
	rm -fr $ORADIR/oradata/XE
fi
if test -d $ORADIR/app/oracle/admin/XE
then
	rm -fr $ORADIR/app/oracle/admin/XE
fi
if test -d $ORADIR/app/oracle/flash_recovery_area/XE
then
	rm -fr $ORADIR/app/oracle/flash_recovery_area/XE
fi

if test -d $ORADIR/app/oracle/admin/cfgtoollogs/dbca/XE
then
	rm -fr $ORADIR/app/oracle/admin/cfgtoollogs/dbca/XE
fi

rm -fr $ORADIR/app/oracle/product/10.2.0/server
rm -fr $ORADIR/app/oracle/doc
rm -fr $PREFIX/share/doc/oracle_xe
rm -fr $PREFIX/share/desktop-menu-files/oraclexe-10g.directory
rm -fr $PREFIX/share/desktop-menu-files/oraclexe-gethelp.directory
rm -fr /var/lib/menu/kde/Applications/OracleXE
rm -fr $PREFIX/share/gnome/vfolders/oraclexe-10g.directory
rm -fr $PREFIX/share/gnome/vfolders/oraclexe-gethelp.directory
if [ -f /etc/xdg/menus/applications.menu ]
then
	rm -f $PREFIX/share/desktop-directories/oraclexe-10g.directory
	rm -f $PREFIX/share/desktop-directories/oraclexe-gethelp.directory
	rm -f /etc/xdg/menus/oraclexe.menu
	
	sed -i "" '/<\!\-- Oracle XE \-->/,/<\!\-- End of Oracle XE \-->/d' /etc/xdg/menus/applications.menu

elif [ -f /etc/X11/desktop-menus/applications.menu ]
then
	sed -i "" '/<\!\-- Oracle XE \-->/,/<\!\-- End of Oracle XE \-->/d' /etc/X11/desktop-menus/applications.menu
elif [ -f /etc/xdg/menus/applications-merged/kde-essential.menu ]
then
	rm -f $PREFIX/share/desktop-directories/oraclexe-10g.directory
	rm -f $PREFIX/share/desktop-directories/oraclexe-gethelp.directory
	rm -f /etc/xdg/menus/oraclexe.menu
	sed -i '/<\!\-- Oracle XE \-->/,/<\!\-- End of Oracle XE \-->/d' /etc/xdg/menus/applications-merged/kde-essential.menu
fi

homedir=`echo $HOME`
if [ "$homedir" = "/root" ]
then
	homedir=`sh -c "echo ~$USER"`
fi

if [ -f $homedir/.gnome-desktop/oraclexe-getstarteddesktop.desktop ]
then
	rm -fr $homedir/.gnome-desktop/oraclexe-getstarteddesktop.desktop
fi

if [ -f $homedir/Desktop/oraclexe-getstarteddesktop.desktop ]
then
	rm -fr $homedir/Desktop/oraclexe-getstarteddesktop.desktop
fi

exit 0
;;

esac

